package com.panshi.controller.audit;

import com.panshi.api.ArticleauditApi;
import com.panshi.po.ArticleauditPo;
import com.panshi.vo.ArticleauditUpdateVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 文章审核修改
 */
@Controller
@Slf4j
public class UpdateAuditController {

    @Autowired
    private ArticleauditApi articleauditApi;


    /**
     * 通过id获取文章审核数据，跳转页面
     * @param id
     * @param model
     * @return
     */
    @GetMapping("upadteAudit")
    public String upadte(@RequestParam Integer id, Model model){

        ArticleauditPo articleauditPo= articleauditApi.idQuery(id).getData();
        model.addAttribute("articleauditPo",articleauditPo);
        return "audit/audit-update";
    }


    /**
     * 文章审核表修改
     * @param articleauditUpdateVo
     * @return
     */
    @PostMapping("audit-upadteAudit")
    @ResponseBody
    public Map<String,Object> upadteAudit(ArticleauditUpdateVo articleauditUpdateVo){

        Map<String,Object> map = new HashMap<>();
        articleauditUpdateVo.setDate(new Date());
        Integer integer=  articleauditApi.updateArticleaudit(articleauditUpdateVo).getData();
        log.info("integer======={}",integer);
        if(integer == -1){
            map.put("success",false);
            map.put("message","修改失败，请重新修改");
        }else if(integer == 1){
            map.put("success",true);
            map.put("message","修改成功");
        }
        return map;
    }






}
